<?php
declare (strict_types = 1);

namespace app;

use think\App;
use think\exception\ValidateException;
use think\Validate;

use app\model\frontend\CustomerModel;
/**
 * 控制器基础类
 */
class FrontendController extends BaseController
{
    public $url_host='';
    public $i = 0; //店铺id : uniacid
    // 初始化
    protected function initialize()
    {

        global $_GPC;
        global $_W;
        
        // $_GPC['i'] = $this->request->param('i/d','') ;
        $_GPC = $this->request->param() ;
        $_W['openid'] = $_GPC['openid']??'';

        if( !empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https' ){
            $REQUEST_SCHEME = 'https';
        }else if( !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ){
            $REQUEST_SCHEME = 'https';
        }else if(! empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ){
            $REQUEST_SCHEME = 'https';
        }else{
            $REQUEST_SCHEME = 'http';
        }

        $this->url_host = $REQUEST_SCHEME .'://'. $_SERVER['HTTP_HOST'];

        // if( !empty($_GPC['openid']) ){
            // $_W['openid'] = $_GPC['openid'];
            // $params = [
            //     'openid'=>$_GPC['openid']
            // ];
        
            // $sql = 'select * from sh_customer_xcx cx inner join sh_customer c on cx.telephone = c.telephone where cx.open_id="' . $_W['openid'] . '"';
            // $_W['customer'] = pdo_fetch( $sql );
            // $_W['platform'] = 'wxapp';
        // }

        //todo 获取用户 doing ~
        if( !empty($_GPC['openid']) ){
            $_W['customer'] = CustomerModel::getCustomer( $_GPC['openid'] );
            $_W['platform'] = 'wxapp';
        }
        $_W['uniacid'] = $this->request->param('i/d','');
        $_GET['i'] = $this->request->param('i/d','');
         
    }

}
